package controller.selection;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.image.BufferedImage;

import gui.ImageButton;

import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;

import component.group.ComponentGroup;

import util.ImageLoader;

public class SelectionPanel extends JPanel {

	private final BufferedImage locked;
	private final BufferedImage unlocked;
	private final BufferedImage trashcan;
	
	private ImageButton lock;
	private ImageButton unlock;
	private ImageButton trash;
	
	private JLabel info;

	public SelectionPanel() {
		this.setOpaque(false);
		this.setBorder(BorderFactory.createEmptyBorder(2, 5, 2, 5));
		ImageLoader loader = new ImageLoader("/resource/image/menu/");
		this.setLayout(new BorderLayout());
		Box box = Box.createHorizontalBox();
		locked = loader.load("locked.png");
		unlocked = loader.load("unlocked.png");
		trashcan = loader.load("trashcan.png");
		
		lock = new ImageButton(locked);
		lock.setToolTipText("Lock selection");
		unlock = new ImageButton(unlocked);
		unlock.setToolTipText("Unlock selection");
		trash = new ImageButton(trashcan);
		trash.setToolTipText("Delete Selection");
		box.add(lock);
		box.add(unlock);
		box.add(trash);
		
		info = new JLabel();
		info.setForeground(Color.white);
		box.add(Box.createHorizontalStrut(5));
		box.add(info);
		box.add(Box.createHorizontalGlue());
		this.add(box, BorderLayout.CENTER);
	}
	
	public JButton getLockButton() {
		return lock;
	}

	public JButton getUnlockButton() {
		return unlock;
	}
	
	public JButton getTrashButton() {
		return trash;
	}
	
	public void setCurrentGroup(ComponentGroup group) {
		if (group == null) {
			info.setText("");
			return;
		}
		String text;
		if (group.isLocked()) {
			text = "Selection is locked";
		} else {
			text = "Selection is not locked";
		}
		
		if (group.hasRoot()) {
			text += " - Selection contains root node";
		}
		
		info.setText(text);
	}

}
